require(zTree)

#Load in some Data
zTT1= zTreeTables("December5compression.xls")
subjects1=zTT1$subjects
subjects1$Subject=subjects1$Subject+100


#Load in some Data
zTT2= zTreeTables("December11compression.xls")
subjects2=zTT2$subjects
subjects2$Subject=subjects2$Subject+200

subjects=rbind(subjects1,subjects2)

#Clean data
subjects$responder=(subjects$"response1[50]">0)
subjects=subset(subjects,responder>0)

uidlist=unique(subjects$Subject)

#find N
#**
length(uidlist)
#**


#create a frame with observations
obsframe=data.frame(uid=vector('numeric'),truenum=vector('numeric'),stnum=vector('numeric'),block=vector('numeric'), number=vector('numeric'), state=vector('numeric'), response=vector('numeric'))
for(i in 1:length(uidlist)){
playframe=subjects[i,]
uidplace=uidlist[i]

#block 1
for (j in 1:50){
blockplace=1
stnumplace=playframe[1,25]
truenumplace=playframe[1,(748+j)]
numberplace=j
stateplace=playframe[1,(998+j)]
responseplace=playframe[1,(84+j)]
addframe=data.frame(uid=uidplace,truenum=truenumplace,stnum=stnumplace,block=blockplace, number=numberplace, state=stateplace, response=responseplace)
obsframe=rbind(obsframe,addframe)
}

#block 2
for (j in 1:50){
blockplace=2
stnumplace=playframe[1,26]
truenumplace=playframe[1,(798+j)]
numberplace=j
stateplace=playframe[1,(1048+j)]
responseplace=playframe[1,(234+j)]
addframe=data.frame(uid=uidplace,truenum=truenumplace,stnum=stnumplace,block=blockplace, number=numberplace, state=stateplace, response=responseplace)
obsframe=rbind(obsframe,addframe)

}

}

obsframe$correct=(obsframe$state==obsframe$response)

#number of states used by different treatments
Nvec=c(2,6)

#States for different treatments
states=list()
states[[1]]=c(4:5)
states[[2]]=c(2:7)



